package com.talent.study.disruptor.height;

import com.lmax.disruptor.RingBuffer;

/**
 * @Author: hszhou
 * @Date: 2025/4/19 14:29
 * @Description: 必须描述类做什么事情, 实现什么功能
 */
public class Producer {

    public RingBuffer<Trade> ringBuffer;

    public Producer(RingBuffer<Trade> ringBuffer){
        this.ringBuffer = ringBuffer;
    }

    public void  sendData(String id){

        long sequence = ringBuffer.next();
        try{

            Trade trade = ringBuffer.get(sequence);
            trade.setId(id);
        }finally {
            ringBuffer.publish(sequence);
        }
    }
}
